package com.woniuxy.controller;

import com.woniuxy.annotation.RequrePerms;
import com.woniuxy.entity.utils.ResponseEntity;
import com.woniuxy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 马宇航
 * @Do: 订单模块controller
 * @DateTime: 22/06/21/0021 下午 3:16
 * @Component: 成都蜗牛学苑
 **/
@RestController
@RefreshScope
public class OrderController {
    @Autowired
    OrderService orderService;
    @Value("${server.port}")
    private int port;
    @Value("${config.myh}")
    private String myh;

    /**
     * 创建一个订单，传入商品id和数量，通过订单去扣减库存！
     * ChangeLog : 1. 创建 (22/06/21/0021 下午 5:33 [马宇航]);
     * @param pid
     * @param count
     * @return com.woniuxy.entity.utils.ResponseEntity
    */
    @GetMapping("/order/{pid}/{count}")
    //自定义注解
    @RequrePerms("order::add")
    public ResponseEntity createOrder(@PathVariable Integer pid,@PathVariable Integer count){
        return orderService.createOne(pid,count);
    }
    @GetMapping("/order")
    @RequrePerms("order::search")
    public ResponseEntity searchProduct(Integer min,Integer max){
        return orderService.searchProduct(min,max);
    }
    @GetMapping("/order/config")
    public ResponseEntity  getPortDynamically(){
        return new ResponseEntity(port+"----"+myh);
    }
}
